package adc.budget.impl.hb.bo;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.HashCodeBuilder;

import adc.budget.spec.bo.IAccount;
import adc.budget.spec.bo.IAccountType;

@Entity
@Table(name="ACCOUNT")
@DiscriminatorValue("ACCOUNT")
public class HbAccount extends HbSource implements IAccount {
    private static final long serialVersionUID = 1L;

    private IAccountType type;
    private Double startingBalance = 0d;

    @Override
    @ManyToOne(targetEntity=HbAccountType.class, optional=false)
    @JoinColumn(name="ACCOUNT_TYPE_ID", nullable=false)
    public IAccountType getType() {
        return type;
    }

    @Override
    public void setType(IAccountType type) {
        this.type = type;
    }

    @Override
    @Column(name="STARTING_BALANCE", nullable=false)
    public Double getStartingBalance() {
        return startingBalance;
    }

    @Override
    public void setStartingBalance(Double startingBalance) {
        this.startingBalance = startingBalance;
    }

    @Override
    public boolean equals(final Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof HbAccount)) {
            return false;
        }
        final HbAccount otherAccount = (HbAccount) other;
        return equals(this.getName(), otherAccount.getName());
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(getName()).toHashCode();
    }
}
